package com.test;

import java.io.IOException;
import java.util.List;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;


import android.content.Context;
import android.os.Bundle;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;

public class WebServiceRequest {

	public Object CallWebService(String methodName, String nameSpace,
			List<String[]> list, String url) {
		String soapAction = nameSpace + methodName;
		SoapObject request = new SoapObject(nameSpace, methodName);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;
		envelope.setOutputSoapObject(request);
		if (list != null) {
			for (int i = 0; i < list.size(); i++) {
				request.addProperty(list.get(i)[0], list.get(i)[1]);
			}
		}
		Log.i("Tag", "NetConnection--->request:" + request);
		HttpTransportSE htppHttpTransportSE = new HttpTransportSE(url);
		String result = null;
		// AndroidHttpTransport transportSE = new AndroidHttpTransport(url);
		try {
			// transportSE.call(soapAction, envelope);
			htppHttpTransportSE.call(soapAction, envelope);
			result = envelope.getResponse().toString();
		} catch (IOException e) {
			//result = AlertMsg.LINK_SERVER_FAILE;
			Log.e("Tag", "NetConnection--->" + e.getMessage());
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			Log.e("Tag", "NetConnection--->XmlPullParserException:" + e.getMessage());
			e.printStackTrace();
		}
		if (result != null) {
			Log.i("Tag", "NetConnection--->result:" + result.toString());
			System.out.println(result.toString());
			return result;
		} else {
			Log.i("Tag", "NetConnection--->返回结果为null");
			return "";
		}

	}
}
